import { IpcHandle, Window } from '@doubleshot/nest-electron'
import { Controller } from '@nestjs/common'
import { BrowserWindow } from 'electron'

@Controller()
export class AppController {
  constructor(@Window() private readonly mainWin: BrowserWindow) {}

  @IpcHandle('close')
  close() {
    this.mainWin.close()
  }

  @IpcHandle('restore')
  restore() {
    if (this.mainWin.isMaximized()) {
      this.mainWin.restore()
    }
  }

  @IpcHandle('maximize')
  maximize() {
    if (!this.mainWin.isMaximized()) {
      this.mainWin.maximize()
    }
  }

  @IpcHandle('minimize')
  minimize() {
    this.mainWin.minimize()
  }
}
